<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>重置区间体检报告</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody" id="popupBody">
        <el-form :model="infoForm" label-width="120px" ref="editForm">
          <el-form-item label="时间区间:">
            <el-date-picker
                v-model="value1"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                size="small">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="年段班级:">
            <component
                v-bind:is="item.propertyType"
                :property.sync="item"
                v-for="(item, index) in getPower"
                :key="index"
                @updateVal="updateVal"
            ></component>
          </el-form-item>
          <el-form-item label="身高调整类型:" prop="num">
            <el-radio-group v-model="infoForm.height_type">
              <el-radio :label="1">升</el-radio>
              <el-radio :label="2">减</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="身高(cm):" prop="num">
            <el-input v-model="infoForm.height" placeholder="身高(cm)可不填" size="small" clearable></el-input>
          </el-form-item>
          <el-form-item label="体重调整类型:" prop="num">
            <el-radio-group v-model="infoForm.weight_type">
              <el-radio :label="1">升</el-radio>
              <el-radio :label="2">减</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="体重(kg):" prop="num">
            <el-input v-model="infoForm.weight" placeholder="体重(kg)可不填" size="small" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定重置</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {studentGrowth} from "@/api/admin/development"

export default {
  props: ['visible'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      value1: [],
      dialogVisible: false,
      infoForm: {
        height: '',
        weight: '',
        height_type: 1,
        weight_type: 1,
        start_time: '',
        end_time: '',
        class_id: '',
        section_id: '',
      },
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '年段', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.value1 = []
        this.infoForm = {
          height: '',
          weight: '',
          height_type: 1,
          weight_type: 1,
          start_time: '',
          end_time: '',
          class_id: '',
          section_id: '',
        }
      }
    }
  },
  created() {

  },
  methods: {
    checkEditFn() {
      console.log(this.value1, this.infoForm)
      let data_ = this.getJson(this.infoForm)
      if (!this.value1 || !this.value1.length) {
        this.$message.error('选择时间区间')
        return
      }
      if (!data_.section_id) {
        this.$message.error('选择需要调整的年段')
        return
      }
      if (!data_.height) {
        data_.height = 0;
      }
      if (!data_.weight) {
        data_.weight = 0;
      }
      data_.start_time = this.value1[0]
      data_.end_time = this.value1[1]
      console.log('data_', data_)
      // this.$emit('checkList', {name: this.itemlable, val: this.infoForm[this.itemlable]})
      // this.closePOpup()
      this.$confirm('确认修改, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        studentGrowth(data_).then(res => {
          if (!res.code) {
            this.$message.success('设置成功')
            this.$emit('InitFn')
            this.closePOpup()
          } else {
            this.$message.error('修改失败，' + res.msg)
          }
        })
      }).catch(() => {
      });
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    updateVal(option) {
      if (option.input) {
        this.infoForm[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.infoForm[option.select[i].name] = option.select[i].valueText
          } else {
            this.infoForm[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}


.jobTime span {
  padding: 0 10px;
}
</style>


